package com.einmeer.kssc_administrator.service.impl;

import com.einmeer.kssc_administrator.entity.purview.Purview;
import com.einmeer.kssc_administrator.entity.purview.PurviewContent;
import com.einmeer.kssc_administrator.mapper.PurviewMapper;
import com.einmeer.kssc_administrator.scconst.PurviewConst;
import com.einmeer.kssc_administrator.service.PurviewService;
import com.einmeer.kssc_administrator.vo.ResultVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 芊嵛
 * @date 2024/2/27
 */
@Service
@Transactional
public class PurviewServiceImpl implements PurviewService {
    @Resource
    private PurviewMapper purviewMapper;

    // 查询所有权限具体内容
    @Override
    public ResultVo queryPurviewContent() {
        List<PurviewContent> purviewContentList = purviewMapper.selectPurviewContent();
        if (purviewContentList.isEmpty()) {
            return new ResultVo(PurviewConst.PurviewNO, PurviewConst.SELECTNO);
        }
        return new ResultVo(PurviewConst.PurviewOK, purviewContentList, PurviewConst.SELECTOK);
    }

    /**
     * 查询所有权限种类
     *
     * @return
     */
    @Override
    public ResultVo queryPurview() {
        List<Purview> purviewList = purviewMapper.selectPurview();
        if (purviewList.isEmpty()) {
            return new ResultVo(PurviewConst.PurviewNO, PurviewConst.SELECTNO);
        }
        return new ResultVo(PurviewConst.PurviewOK, purviewList, PurviewConst.SELECTOK);
    }

    /**
     * 用于修改权限，根据id查询权限
     *
     * @param purviewId
     * @return
     */
    @Override
    public ResultVo queryPurviewContentId(Integer purviewId) {
        List<PurviewContent> purviewContentList = purviewMapper.selectPurviewContentId(purviewId);
        if (purviewContentList.isEmpty()) {
            return new ResultVo(PurviewConst.PurviewNO, PurviewConst.SELECTNO);
        }
        return new ResultVo(PurviewConst.PurviewOK, purviewContentList, PurviewConst.SELECTOK);
    }

    /**
     * 修改停用与启用
     *
     * @param purviewId
     * @param purviewState
     * @return
     */
    @Override
    public ResultVo changePurviewState(Integer purviewId, Integer purviewState) {
        purviewState = purviewState==1?0:1;
        int n = purviewMapper.updatePurviewState(purviewId, purviewState);
        if (n == 1) {
            return new ResultVo(PurviewConst.PurviewOK,purviewState, PurviewConst.UPDATEOK);
        }
        return new ResultVo(PurviewConst.PurviewNO, PurviewConst.UPDATENO);
    }
}
